package com.ss.android.article.browser.view.multiselect.viewholder;

import android.content.Context;
import android.support.v4.view.MotionEventCompat;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public final class d extends FrameLayout {
    boolean a;
    @NotNull
    final Runnable b;
    private final int c;
    private final long d;
    private float e;
    private float f;
    private float g;
    private float h;
    private long i;
    private boolean j;
    private BingoCallback k;
    private BingoCallback l;
    @NotNull
    private final com.ss.android.article.browser.view.multiselect.a m;

    public d(@NotNull Context context, @NotNull com.ss.android.article.browser.view.multiselect.a adapter, @NotNull View child) {
        super(context);
        int v2 = -1;
        this.m = adapter;
        this.c = ViewConfiguration.get(context).getScaledTouchSlop();
        this.d = ((long) ViewConfiguration.getLongPressTimeout());
        this.b = new f(this);
        ViewGroup.LayoutParams v1 = child.getLayoutParams();
        FrameLayout.LayoutParams v0 = v1 != null ? new FrameLayout.LayoutParams(v1) : new FrameLayout.LayoutParams(v2, v2);
        this.setLayoutParams(((ViewGroup.LayoutParams) v0));
        this.addView(child);
    }

    @Nullable
    public static final BingoCallback a(d arg1) {
        return arg1.k;
    }

    private final boolean a() {
        float v0 = Math.abs(this.e - this.g);
        float v1 = Math.abs(this.f - this.h);
        boolean v0_1 = v0 > (((float) this.c)) || v1 > (((float) this.c)) ? false : true;
        return v0_1;
    }

    public static final boolean b(d arg1) {
        return arg1.a();
    }

    public final boolean dispatchTouchEvent(@Nullable MotionEvent arg2) {
        return super.dispatchTouchEvent(arg2);
    }

    @NotNull
    public final com.ss.android.article.browser.view.multiselect.a getAdapter() {
        return this.m;
    }

    public final int getCLICK_ACTION_THRESHHOLD() {
        return this.c;
    }

    public final long getCLICK_LONG_TIME() {
        return this.d;
    }

    public final long getDownTime() {
        return this.i;
    }

    public final boolean getMHasPerformedLongPress() {
        return this.j;
    }

    public final float getMoveX() {
        return this.g;
    }

    public final float getMoveY() {
        return this.h;
    }

    @NotNull
    public final Runnable getRun() {
        return this.b;
    }

    public final float getStartX() {
        return this.e;
    }

    public final float getStartY() {
        return this.f;
    }

    public final boolean onInterceptTouchEvent(@NotNull MotionEvent ev) {
        int v0;
        boolean v2 = false;
        switch (MotionEventCompat.getActionMasked(ev)) {
            case 0: {
                this.j = false;
                this.a = true;
                this.e = ev.getX();
                this.f = ev.getY();
                this.g = ev.getX();
                this.h = ev.getY();
                this.i = System.currentTimeMillis();
                this.postDelayed(this.b, this.d);
                v0 = 0;
                break;
            }
            case 2: {
                this.g = ev.getX();
                this.h = ev.getY();
                v0 = System.currentTimeMillis() - this.i > this.d ? 1 : 0;
                if (v0 == 0) {
                    v0 = 0;
                    break;
                }

                if (!this.a()) {
                    v0 = 0;
                    break;
                }

                v0 = 1;
                break;
            }
            case 1:
            case 3: {
                this.a = false;
                this.removeCallbacks(this.b);
                v0 = 0;
                break;
            }
            default:
                v0 = 0;
                break;
        }


        if (v0 != 0 || this.m.a == com.ss.android.article.browser.view.multiselect.g.c()) {
            v2 = true;
        }
        return v2;
    }

    public final boolean onTouchEvent(@NotNull MotionEvent ev) {
        int v0 = MotionEventCompat.getActionMasked(ev);
        switch (v0) {
            case 0: {
                this.a = true;
                this.j = false;
                this.e = ev.getX();
                this.f = ev.getY();
                this.g = ev.getX();
                this.h = ev.getY();
                break;
            }
            case 2: {
                this.g = ev.getX();
                this.h = ev.getY();
                break;
            }
            case 1:
            case 3: {
                this.a = false;
                this.removeCallbacks(this.b);
                if (v0 != 1) {
                    return true;
                }

                if (!this.a()) {
                    return true;
                }

                BingoCallback v0_1 = this.l;
                if (v0_1 == null) {
                    return true;
                }

                v0_1.invoke();
                break;
            }
        }

        return true;
    }

    public final void setDownTime(long arg2) {
        this.i = arg2;
    }

    public final void setLongClickCallback(@NotNull BingoCallback callback) {
        this.k = callback;
    }

    public final void setMHasPerformedLongPress(boolean arg1) {
        this.j = arg1;
    }

    public final void setMoveX(float arg1) {
        this.g = arg1;
    }

    public final void setMoveY(float arg1) {
        this.h = arg1;
    }

    public final void setSelectStateClickCallback(@NotNull BingoCallback callback) {
        this.l = callback;
    }

    public final void setStartX(float arg1) {
        this.e = arg1;
    }

    public final void setStartY(float arg1) {
        this.f = arg1;
    }

    public final void setTouching(boolean arg1) {
        this.a = arg1;
    }
}

